package com.iknow.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.data.IdentityFlag;
import com.iknow.ui.model.IndentityFlagAdapter;
import com.iknow.util.StringUtil;

public class IndentityFlagActivity extends Activity
{
  private View.OnClickListener AddBtnClickListener;
  private View.OnClickListener SaveBtnClickListener;
  private IndentityFlagAdapter mAdapter;
  private Button mAddButton;
  private Button mBackButton;
  private Context mContext;
  private EditText mFlagEditText;
  private GridView mFlagGridView;
  private String mFlags;
  private Button mSaveBtn;

  public IndentityFlagActivity()
  {
    this.AddBtnClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (!(IKnow.IsNetAviable()))
          Toast.makeText(IndentityFlagActivity.access$0(this.this$0), IndentityFlagActivity.access$0(this.this$0).getResources().getString(2131361878), 0).show();
        while (true)
        {
          String str;
          while (true)
          {
            return;
            str = IndentityFlagActivity.access$1(this.this$0).getText().toString();
            if (!(StringUtil.isEmpty(str)))
              break;
            Toast.makeText(this.this$0, "请先输入标签", 0).show();
          }
          IdentityFlag localIdentityFlag = new IdentityFlag(String.valueOf(IndentityFlagActivity.access$2(this.this$0).getCount()), str);
          localIdentityFlag.setSelected(true);
          IndentityFlagActivity.access$2(this.this$0).addFlag(localIdentityFlag);
          IndentityFlagActivity.access$2(this.this$0).notifyDataSetChanged();
          IndentityFlagActivity.access$1(this.this$0).setText("");
        }
      }
    };
    this.SaveBtnClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (!(IKnow.IsNetAviable()))
          Toast.makeText(IndentityFlagActivity.access$0(this.this$0), IndentityFlagActivity.access$0(this.this$0).getResources().getString(2131361878), 0).show();
        while (true)
        {
          return;
          String str = IndentityFlagActivity.access$2(this.this$0).getFlags();
          this.this$0.getIntent().setAction(str);
          this.this$0.setResult(-1, this.this$0.getIntent());
          this.this$0.finish();
        }
      }
    };
  }

  private void initData()
  {
    String[] arrayOfString2;
    int j;
    if (!(StringUtil.isEmpty(this.mFlags)))
    {
      arrayOfString2 = this.mFlags.split("，");
      j = arrayOfString2.length - 1;
      if (j >= 0)
        break label59;
    }
    String[] arrayOfString1 = getResources().getStringArray(2131099649);
    int i = 0;
    while (true)
    {
      while (i >= arrayOfString1.length)
      {
        this.mAdapter.notifyDataSetChanged();
        return;
        label59: IdentityFlag localIdentityFlag2 = new IdentityFlag(String.valueOf(j + this.mAdapter.getCount()), arrayOfString2[j]);
        localIdentityFlag2.setSelected(true);
        this.mAdapter.addFlag(localIdentityFlag2);
        --j;
      }
      IdentityFlag localIdentityFlag1 = new IdentityFlag(String.valueOf(i), arrayOfString1[i]);
      this.mAdapter.addFlag(localIdentityFlag1);
      ++i;
    }
  }

  private void initView()
  {
    requestWindowFeature(1);
    setContentView(2130903134);
    this.mFlagGridView = ((GridView)findViewById(2131296587));
    this.mFlagEditText = ((EditText)findViewById(2131296586));
    this.mAddButton = ((Button)findViewById(2131296329));
    this.mAddButton.setOnClickListener(this.AddBtnClickListener);
    this.mAdapter = new IndentityFlagAdapter(getLayoutInflater());
    this.mFlagGridView.setAdapter(this.mAdapter);
    this.mFlagGridView.setOnItemClickListener(new AdapterView.OnItemClickListener(this)
    {
      public void onItemClick(, View paramView, int paramInt, long paramLong)
      {
        RelativeLayout localRelativeLayout = (RelativeLayout)paramView;
        IdentityFlag localIdentityFlag = IndentityFlagActivity.access$2(this.this$0).getItem(paramInt);
        if (localIdentityFlag.IsFlagSelected())
        {
          localIdentityFlag.setSelected(false);
          localRelativeLayout.setBackgroundResource(2130837572);
        }
        while (true)
        {
          localRelativeLayout.invalidate();
          return;
          localIdentityFlag.setSelected(true);
          localRelativeLayout.setBackgroundResource(2130837574);
        }
      }
    });
    this.mSaveBtn = ((Button)findViewById(2131296344));
    this.mSaveBtn.setVisibility(0);
    this.mSaveBtn.setText("保存");
    this.mSaveBtn.setOnClickListener(this.SaveBtnClickListener);
    this.mBackButton = ((Button)findViewById(2131296342));
    this.mBackButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.this$0.finish();
      }
    });
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.mContext = this;
    this.mFlags = getIntent().getStringExtra("flag");
    initView();
    initData();
  }
}